package netty.nio.netty.decoder;

import netty.nio.netty.protocol.NotEnoughBytesException;

import java.io.ByteArrayOutputStream;

public class TransportDecoder<T> implements StreamDecoder<T> {
    private ByteArrayOutputStream body;

    public TransportDecoder() {

    }

    @Override
    public void init(int availableBytes) throws Exception {

        if (availableBytes < 4) {
            throw new NotEnoughBytesException("Netty Server: Not enough available bytes: " + availableBytes);
        }

        // Тело сообщения
        body = new ByteArrayOutputStream();

    }

    @Override
    public void addByte( byte b ) throws Exception {

        body.write( b );

    }

    @Override
    public T decode() {
        return null;
    }

    @Override
    public byte[] getAddedBytes() {

        return body.toByteArray();

    }

    @Override
    public boolean enough() {
        return false;
    }
}
